package com.teyao.teyao_back.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teyao.teyao_back.config.myPage;
import com.teyao.teyao_back.entity.CarClientWrapper;
import com.teyao.teyao_back.entity.ResponseMessage;
import com.teyao.teyao_back.mapper.CarClientMapper;
import com.teyao.teyao_back.service.CarClientService;
import org.springframework.stereotype.Service;

@Service
public class CarClientImpl extends ServiceImpl<CarClientMapper, CarClientWrapper> implements CarClientService {
    //获取工作动态
    @Override
    public ResponseMessage getAll() {
        QueryWrapper<CarClientWrapper> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("driver_name", "");
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setSuccess(true);
        responseMessage.setData(baseMapper.selectList(queryWrapper));
        return responseMessage;
    }

    @Override
    public myPage myQuery(Integer currentPage, Integer size, CarClientWrapper carClientWrapper) {
        myPage myPage = new myPage();
        myPage.setCurrentPage(currentPage);
        Page<CarClientWrapper> page = new Page<>(currentPage, size);
        QueryWrapper<CarClientWrapper> queryWrapper = new QueryWrapper<>();
        if (carClientWrapper.getOrderId() != null && !carClientWrapper.getOrderId().isBlank()) {
            queryWrapper.like("order_id", carClientWrapper.getOrderId().trim());
        }
        if (carClientWrapper.getStatus() != null && !carClientWrapper.getStatus().isBlank()) {
            queryWrapper.like("status", carClientWrapper.getStatus());
        }
        queryWrapper.eq("driver_id", carClientWrapper.getDriverId()).ne("status", "已签收");
        IPage iPage = baseMapper.selectPage(page, queryWrapper);
        myPage.setData(iPage.getRecords());
        myPage.setTotal((int) iPage.getTotal());
        return myPage;
    }

    @Override
    public myPage alreadyQuery(Integer currentPage, Integer size, CarClientWrapper carClientWrapper) {
        myPage myPage = new myPage();
        myPage.setCurrentPage(currentPage);
        Page<CarClientWrapper> page = new Page<>(currentPage, size);
        QueryWrapper<CarClientWrapper> queryWrapper = new QueryWrapper<>();
        if (carClientWrapper.getOrderId() != null && !carClientWrapper.getOrderId().isBlank()) {
            queryWrapper.like("order_id", carClientWrapper.getOrderId().trim());
        }
        queryWrapper.eq("driver_id", carClientWrapper.getDriverId()).eq("status", "已签收");
        IPage iPage = baseMapper.selectPage(page, queryWrapper);
        myPage.setData(iPage.getRecords());
        myPage.setTotal((int) iPage.getTotal());
        return myPage;
    }
}
